package com.housekeeping.housekeeping.advertisingmanagement.service.impl;/*
 * @author  pyh
 * @date  2021/1/18 0018 下午 9:41
 * @version 1.0
 * @since JDK1.8_241
 */

import com.housekeeping.housekeeping.advertisingmanagement.dao.OperationDao;
import com.housekeeping.housekeeping.advertisingmanagement.dao.impl.OperationDaoImpl;
import com.housekeeping.housekeeping.advertisingmanagement.service.AdMessagesService;
import com.housekeeping.housekeeping.advertisingmanagement.entity.AdMessages;
import com.housekeeping.housekeeping.advertisingmanagement.utils.Page;

import java.sql.SQLException;
import java.util.List;

public class AdMessagesServiceImpl implements AdMessagesService {
    private OperationDao operationDao1 = new OperationDaoImpl();
    //private OperationDao operationDao2 = new SelectDao();
    @Override
    public int saveAdMessages(AdMessages adMessages) {
        int count = operationDao1.insert(adMessages);
        return count;
    }

    @Override
    public Page<AdMessages> list(int page, int size) throws SQLException {
        List<AdMessages> categories = operationDao1.selectByPage((page - 1) * size, size);
        //查询总页数
        int count = operationDao1.selectCount();
        Page<AdMessages> pageBean = new Page<>(page, size, count);
        pageBean.setData(categories);
        return pageBean;
    }

    @Override
    public AdMessages findCate(int id) {
        return null;
    }

    @Override
    public void add(AdMessages adMessages) {
        operationDao1.insert(adMessages);
    }
    //删除
    @Override
    public int del(int id) {
        int del = operationDao1.delete(id);
        return del;
    }

    @Override
    public AdMessages update(int id) {
        AdMessages update = operationDao1.update(id);
        return update;
    }
    //通过广告名称查询广告表
    @Override
    public List<AdMessages> getAdMessagesList(String name) throws SQLException {
        List<AdMessages> AdContent = operationDao1.selectByKey(name);
        //数据库操作
        return AdContent;
    }

}
